﻿using Sasa.QualityTools.CodeAnalysis.Common;
using Sasa.QualityTools.CodeAnalysis.FxCopIntegrator.ViewModels;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace Sasa.QualityTools.CodeAnalysis.FxCopIntegrator.UI
{
    public partial class CodeAnalysisResultContent : UserControl
    {
        public CodeAnalysisResultContent()
        {
            InitializeComponent();
        }


        private void OnProblemDoubleClicked(object sender, MouseButtonEventArgs e)
        {
            Logger.Info("Began to focus the violation source code.");

            var problem = ((ListViewItem)sender).Content as ProblemViewModel;
            if (problem == null)
            {
                Logger.Warn("Failed to focus because the double-clicked content is not bound to any violation information.");
                return;
            }

            var viewModel = (CodeAnalysisResultViewModel)DataContext;
            viewModel.FocusRelatedCode(problem);
            viewModel.ShowRule(viewModel.Rules[problem.CheckId]);

            e.Handled = true;
        }

        private void ToggleHowToSearchPopupVisibility(object sender, RoutedEventArgs e)
        {
            this.howToSearchPopup.IsOpen = !this.howToSearchPopup.IsOpen;
        }
    }
}
